package com.newdriver.edu.inf.manager.dao;

import com.newdriver.edu.inf.manager.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teachers=new Teacher[5];

    public void deleteTeaById(String delId) {
        int index=getIndex(delId);
        teachers[index]=null;
    }

    public int getIndex(String id) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher!=null&&teacher.getId().equals(id)) {
                index=i;
                break;
            }
        }return index;
    }


    public boolean addTeacher(Teacher teacher) {
        int index=-1;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teach = teachers[i];
            if (teach == null) {
                index=i;
                break;
            }
        }
        if (index==-1){
            return false;
        }   else{
            teachers[index]=teacher;
            return true;
        }
    }


    public Teacher[] findAllTeacher() {
        return teachers;
    }


    public void updateTeacher(String updateId, Teacher teacher) {
        int index =getIndex(updateId);
        teachers[index]=teacher;
    }
}
